package com.anniljing.kotlionlearn.Basic.controlFlow

fun main() {
//    whenDemo(10)
//    breakDemo()
    foo()
}

fun whenDemo(x: Int) {
    when (x) {
        1 -> println("1")
        2 -> println("2")
        else -> println("$x")

    }
}

fun breakDemo() {
    loop@ for (i in 1..100) {
        if (i % 2 == 0) {
            continue@loop
        }
        println(i)
    }
}

fun foo() {
    run loop@{
        listOf(1, 2, 3, 4, 5).forEach {
            if (it == 3) return@loop // non-local return from the lambda passed to run
            println(it)
        }
    }
    println(" done with nested loop")
}